home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / space / sols.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  46KB  |  1,474 lines

  1. /*
  2.  * Copyright (C) 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "space.h"
  18.  
  19. P4      feye ;
  20. V3      lit ;
  21. flot32  vids ;
  22. t_body  *planet ;
  23.  
  24. char  mem_col_nme[32] ;
  25. char  mem_ele_nme[32] ;
  26. char *mem_col_ptr ;
  27. char *mem_ele_ptr ;
  28.  
  29. extern t_stopwatch Counter ;
  30. extern V4        plum[NUM_CLIP_PLANES] ;
  31. extern t_galaga  ggaa[STARSQ][STARSQ] ;
  32. extern flot32    lut[4096] ;
  33. extern char      StarName[NUMBER_OF_STARS][16] ;
  34. extern t_const   constellation ;
  35. extern int       GeosphereData ;
  36.  
  37. /**********************************************************************
  38. *  actually_do_graphics()  - 
  39. ***********************************************************************/
  40. void actually_do_graphics(t_boss *flaggs)
  41.  
  42. {  register flot32 w ;
  43.  
  44.    Counter.flags &= ~GEOSP_FLAG ;
  45.  
  46.    glMatrixMode(GL_MODELVIEW) ;
  47.    glLoadIdentity();
  48.    glLoadMatrixf((float *)Counter.mat);
  49.  
  50.    switch (Counter.status)  {
  51.      case STELL_STAT: special_perspective(0.02,1.0e6) ;
  52.                       spSetLight(&Counter.light_vector);
  53.  
  54.                       display_stellar_background(flaggs) ;
  55.  
  56.                       if (!(Counter.flags & (PRBIT_FLAG | MRBIT_FLAG) == (PRBIT_FLAG | MRBIT_FLAG)))
  57.                         display_foreground(flaggs) ;
  58.                       break ;
  59.  
  60.      case GALAC_STAT: special_perspective(0.13,33000.0) ;
  61.                       display_galactic_background() ;
  62.                       break ;
  63.  
  64.      case COSMC_STAT: w = Counter.eye.x*Counter.eye.x+Counter.eye.y*Counter.eye.y+Counter.eye.z*Counter.eye.z ;
  65.                       if (w > GALAXY_EDGE*GALAXY_EDGE/4.0)  {
  66.                         w = fsqrt(w) ;
  67.                         special_perspective(w-0.5*GALAXY_EDGE,w+0.5*GALAXY_EDGE) ;
  68.                         }
  69.                       else special_perspective(1.0,33000.0) ;
  70.  
  71.                       display_cosmic_background() ;
  72.                       break ;
  73.  
  74.      default        : printf("INTERNAL ERROR: actually_do_graphics() - Unsupported status\n") ;
  75.                       exit(0) ;
  76.                       break ;
  77.      }
  78. }
  79.  
  80. /**********************************************************************
  81. *  display_stellar_background()  - 
  82. **********************************************************************/
  83. static void display_stellar_background(t_boss *flaggs)
  84.  
  85. {  register sint32 i,k,lim,dd[3] ;
  86.    register t_body *tb,*tc ;
  87.    register uchar8 cl[4];
  88.  
  89.    if (Counter.flags & ZODAC_FLAG && Counter.z == SOL_Z_GRID && Counter.x == SOL_X_GRID && Counter.star_current == 0) {
  90.      if (!(Counter.alpha & HW_MULSA) && (Counter.alpha & HW_AALIN)) {
  91.        glBlendFunc(GL_SRC_ALPHA, GL_ZERO);  
  92.        glEnable(GL_BLEND);
  93.        }
  94.  
  95.      glCallList(Counter.constobj);
  96.   
  97.      if (!(Counter.alpha & HW_MULSA) && (Counter.alpha & HW_AALIN)) {
  98.        glBlendFunc(GL_SRC_ALPHA, GL_ONE);  
  99.        glDisable(GL_BLEND);
  100.        }
  101.      }
  102.  
  103.    if (Counter.flags & STNAM_FLAG)
  104.      display_star_names() ;
  105.  
  106.    if (Counter.skyfrac < 160.0)  {
  107.      glCallList(Counter.locun);
  108.  
  109.      if (Counter.alpha & HW_AAPNT)
  110.        glEnable(GL_BLEND);
  111.  
  112.      glBegin(GL_POINTS) ;
  113.      for (k=0; k<flaggs->suncount; k++)  {
  114.        for (i=0; i<flaggs->star[k].ptr->moon_count; i++)  {
  115.          tb = (t_body *)flaggs->star[k].next[i] ;
  116.   
  117.          if ((i != flaggs->plan_current || k != flaggs->suun_current) || (tb->angsiz < ANGULAR_SIZE)) {
  118.            cl[0] = (tb->color >>  0) & 0xff;
  119.            cl[1] = (tb->color >>  8) & 0xff;
  120.            cl[2] = (tb->color >> 16) & 0xff;
  121.            cl[3] = (tb->color >> 24) & 0xff;
  122.            glColor4ubv(cl) ;
  123.            glVertex3dv(&tb->posit.x) ;
  124.            }
  125.          }
  126.  
  127.        if (flaggs->star[k].angsiz < ANGULAR_SIZE) {
  128.          cl[0] = (flaggs->star[k].ptr->col >>  0) & 0xff;
  129.          cl[1] = (flaggs->star[k].ptr->col >>  8) & 0xff;
  130.          cl[2] = (flaggs->star[k].ptr->col >> 16) & 0xff;
  131.          cl[3] = (flaggs->star[k].ptr->col >> 24) & 0xff;
  132.          glColor4ubv(cl) ;
  133.          glVertex3dv(&flaggs->star[k].posit.x) ;
  134.          }
  135.        }
  136.      glEnd() ;
  137.  
  138.      if (Counter.alpha & HW_AAPNT)
  139.        glDisable(GL_BLEND);
  140.      }
  141.  
  142.    /* draw sun(s) */
  143.    if (Counter.flags & RINGW_FLAG) 
  144.      ;
  145.    else  {
  146.      if (flaggs->suncount == 2 && flaggs->star[1].distan > flaggs->star[0].distan)  {
  147.        dd[0] = flaggs->suncount-1; dd[1] = -1; dd[2] = -1;
  148.        }
  149.      else  {
  150.        dd[0] = 0; dd[1] = flaggs->suncount; dd[2] = 1;
  151.        }
  152.  
  153.      for (k=dd[0]; k!=dd[1]; k+=dd[2])
  154.        if (flaggs->star[k].angsiz >= ANGULAR_SIZE)  {
  155.          if ((Counter.flags & ECLIP_FLAG) && !(Counter.flags & (PRBIT_FLAG | MRBIT_FLAG)))  {
  156.            if (Counter.feclipse > 0.9)
  157.              total_solar_eclipse(flaggs) ;
  158.            if (Counter.feclipse < 1.0)
  159.              draw_me(&flaggs->star[k],flaggs) ;
  160.            }
  161.          else draw_me(&flaggs->star[k],flaggs) ;
  162.          }
  163.      }
  164.  
  165.    /* draw away moons */
  166.    if (flaggs->plan_current >= 0 && !(Counter.flags & MRBIT_FLAG)) {
  167.      tb = (t_body *) flaggs->star[flaggs->suun_current].next[flaggs->plan_current] ;
  168.  
  169.      if (Counter.alpha & HW_AAPNT)
  170.        glEnable(GL_BLEND);
  171.  
  172.      /* draw point moons */
  173.      glBegin(GL_POINTS) ;
  174.      for (i=0; i<tb->ptr->moon_count; i++) {
  175.        tc = (t_body *) tb->next[i] ;
  176.   
  177.        if (tc->angsiz < ANGULAR_SIZE && tc->distan > tb->distan)  {
  178.          cl[0] = (tc->color >>  0) & 0xff;
  179.          cl[1] = (tc->color >>  8) & 0xff;
  180.          cl[2] = (tc->color >> 16) & 0xff;
  181.          cl[3] = (tc->color >> 24) & 0xff;
  182.          glColor4ubv(cl) ;
  183.          glVertex3dv(&tc->posit.x) ;
  184.          }
  185.        }
  186.      glEnd() ;
  187.  
  188.      if (Counter.alpha & HW_AAPNT)
  189.        glDisable(GL_BLEND);
  190.  
  191.      /* draw sphere moons */
  192.      for (i=0; i<tb->ptr->moon_count; i++)  {
  193.        tc = (t_body *) tb->next[i] ;
  194.   
  195.        if (tc->angsiz >= ANGULAR_SIZE && tc->distan > tb->distan)
  196.          draw_me(tc,flaggs) ;
  197.        }
  198.      }
  199.  
  200.    if (Counter.flags & (PRBIT_FLAG | MRBIT_FLAG))
  201.      polyline_orbits(flaggs) ;
  202. }
  203.  
  204. /**********************************************************************
  205. *  display_galactic_background()  - 
  206. **********************************************************************/
  207. static void display_galactic_background(void)
  208.  
  209. {  
  210.    if (Counter.flags & STNAM_FLAG)
  211.      display_star_names() ;
  212.  
  213.    draw_all_them_stars(1);
  214. }
  215.  
  216. /**********************************************************************
  217. *  display_cosmic_background()  - 
  218. **********************************************************************/
  219. static void display_cosmic_background(void)
  220.  
  221. {  register flot32 scsps[8] ;
  222.  
  223.    glShadeModel(GL_SMOOTH);
  224.    glPushMatrix() ;
  225.    glTranslatef(-Counter.eye.x,-Counter.eye.y,-Counter.eye.z) ;
  226.  
  227.    if (Counter.flags & TEXTR_FLAG)  {
  228.      glEnable(GL_DEPTH_TEST);
  229.      spFlipTex(1,Counter.galaxy) ;
  230.  
  231.      glColor4f(1.0,1.0,1.0,1.0) ;
  232.  
  233.      glCullFace(GL_FRONT) ;
  234.      glCallList(Counter.galobj[1]) ;
  235.      glCullFace(GL_BACK) ;
  236.      glScalef(1.0,-1.0,1.0) ;
  237.      glCallList(Counter.galobj[1]) ;
  238.  
  239.      spFlipTex(0,0) ;
  240.      glDisable(GL_DEPTH_TEST);
  241.      }
  242.    else if (Counter.flags & SLOWZ_FLAG)  {
  243.      glCullFace(GL_FRONT) ;
  244.      glScalef(1.0,0.0,1.0) ;
  245.      glCallList(Counter.galobj[0]) ;
  246.      glCullFace(GL_BACK) ;
  247.      }
  248.    else  {
  249.      glEnable(GL_DEPTH_TEST);
  250.  
  251.      glCullFace(GL_FRONT) ;
  252.      glCallList(Counter.galobj[0]) ;
  253.      glCullFace(GL_BACK) ;
  254.      glScalef(1.0,-1.0,1.0) ;
  255.      glCallList(Counter.galobj[0]) ;
  256.  
  257.      glDisable(GL_DEPTH_TEST);
  258.      }
  259.  
  260.    glPopMatrix() ;
  261.    glShadeModel(GL_FLAT);
  262. }
  263.  
  264. /**********************************************************************
  265. *  display_foreground()  -
  266. **********************************************************************/
  267. static void display_foreground(t_boss *flaggs)
  268.  
  269. {  register sint32 i,draw_st,draw_pl ;
  270.    register flot32 w,z,min,max ;
  271.    register flot64 theta ;
  272.    register t_body *tb,*tc ;
  273.    register uchar8 cl[4];
  274.  
  275.    if (flaggs->plan_current < 0)
  276.      return ;
  277.  
  278.    tb = (t_body *) flaggs->star[flaggs->suun_current].next[flaggs->plan_current] ;
  279.  
  280.    if (((tb->ptr->tess >> 4) & 0x0f) == FRAC_RINGWO)  {
  281.      display_ringworld_foreground(flaggs);
  282.      return;
  283.      }
  284.  
  285.    if (!(Counter.flags & PRBIT_FLAG))  {
  286.      draw_st = 0 ;
  287.      draw_pl = 0 ;
  288.  
  289.      /* check space station drawing */
  290.      if (Counter.star_current == 0 && flaggs->plan_current == 2 && flaggs->stat.angsiz >= 2.0*ANGULAR_SIZE)
  291.        if (sphere_clipp(&flaggs->stat.posit,flaggs->stat.cliprad))
  292.          draw_st = 1 ;
  293.  
  294.      i = (tb->ptr->tess & 0x00f0) >> 4 ;
  295.      if (tb->ptr->r2 != 0.0)
  296.        draw_pl |= 0x1 ;
  297.      if (i == FRAC_PLANET || i == ELEV_PLANET)
  298.        draw_pl |= 0x2 ;
  299.  
  300.      if (tb->ptr->r2 != 0.0)  {
  301.        max = 1.05*(tb->distan + tb->ptr->r2) ;
  302.        min = 0.90*(tb->distan - tb->ptr->r2) ;
  303.        }
  304.      else  {
  305.        max = 1.05*(tb->distan + tb->ptr->rad) ;
  306.        min = 0.90*(tb->distan - 1.25*tb->ptr->rad) ;
  307.        }
  308.   
  309.      if (draw_st)
  310.        min = 10.0 ;
  311.      else if (min < 1.0)
  312.        min = 1.0 ;
  313.  
  314.      if (draw_st || draw_pl & 0x1) 
  315.        glEnable(GL_DEPTH_TEST);
  316.      else if (draw_pl & 0x2)  {
  317.        if (Counter.flags & SLOWZ_FLAG) {
  318.          if (vids < 2.5)
  319.            glEnable(GL_DEPTH_TEST);
  320.          }
  321.        else glEnable(GL_DEPTH_TEST);
  322.        }
  323.  
  324.      special_perspective(min,max) ;
  325.  
  326.      /* draw space station */
  327.      if (draw_st)  {
  328.        spLightMaterial(1,~0);
  329.  
  330.        glPushMatrix() ;
  331.        glTranslatef(flaggs->stat.posit.x,flaggs->stat.posit.y,flaggs->stat.posit.z) ;
  332.  
  333.        theta = 24.0*60.0*Counter.D ;
  334.        i = theta ;
  335.        theta = 360.0*(theta - i) ;
  336.        glRotatef(theta,0.0,1.0,0.0) ; 
  337.  
  338.        glShadeModel(GL_SMOOTH);
  339.        spFlipTex(1,flaggs->stat.texdf) ;
  340.  
  341.        if (flaggs->stat.angsiz >= 0.08)
  342.          glCallList(flaggs->stat.bodyobj[0]) ;
  343.        else if (flaggs->stat.angsiz >= 0.015)
  344.          glCallList(flaggs->stat.bodyobj[1]) ;
  345.        else glCallList(flaggs->stat.bodyobj[2]) ;
  346.  
  347.        spFlipTex(0,0) ;
  348.        glShadeModel(GL_FLAT);
  349.  
  350.        glPopMatrix() ;
  351.  
  352.        spLightMaterial(0,~0);
  353.        }
  354.  
  355.      /* draw planet */
  356.      if (tb->angsiz >= ANGULAR_SIZE)
  357.        draw_me(tb,flaggs) ;
  358.  
  359.      glDisable(GL_DEPTH_TEST);
  360.      }
  361.  
  362.    /* draw near moons */
  363.    if (!(Counter.flags & MRBIT_FLAG)) {
  364.      special_perspective(0.02,1.0e6) ;
  365.  
  366.      /* draw point moons */
  367.      if (Counter.alpha & HW_AAPNT)
  368.        glEnable(GL_BLEND);
  369.  
  370.      glBegin(GL_POINTS) ;
  371.      for (i=0; i<tb->ptr->moon_count; i++) {
  372.        tc = (t_body *) tb->next[i] ;
  373.   
  374.        if (tc->angsiz < ANGULAR_SIZE && tc->distan <= tb->distan)  {
  375.          cl[0] = (tc->color >>  0) & 0xff;
  376.          cl[1] = (tc->color >>  8) & 0xff;
  377.          cl[2] = (tc->color >> 16) & 0xff;
  378.          cl[3] = (tc->color >> 24) & 0xff;
  379.          glColor4ubv(cl) ;
  380.          glVertex3dv(&tc->posit.x) ;
  381.          }
  382.        }
  383.      glEnd() ;
  384.  
  385.      if (Counter.alpha & HW_AAPNT)
  386.        glDisable(GL_BLEND);
  387.  
  388.      /* draw sphere moons */
  389.      for (i=0; i<tb->ptr->moon_count; i++)  {
  390.        tc = (t_body *) tb->next[i] ;
  391.   
  392.        if (tc->angsiz >= ANGULAR_SIZE && tc->distan <= tb->distan) 
  393.          draw_me(tc,flaggs) ;
  394.        }
  395.      }
  396. }
  397.  
  398. /**********************************************************************
  399. *  display_ringworld_foreground()  -
  400. **********************************************************************/
  401. static void display_ringworld_foreground(t_boss *flaggs)
  402.  
  403. {  register sint32 i ;
  404.    register flot32 w,z,arr[4] ;
  405.    register flot64 theta ;
  406.    register t_body *tb ;
  407.    register D3     *p; ;
  408.  
  409.    tb = (t_body *) flaggs->star[flaggs->suun_current].next[flaggs->plan_current] ;
  410.  
  411.    w = flaggs->star[flaggs->suun_current].distan ;
  412.    z = 1.05 * tb->ptr->orb ;
  413.  
  414.    if (w < z) 
  415.      special_perspective(1.0e2,z+z) ;
  416.    else special_perspective(w-z,w+z) ;
  417.  
  418.    glEnable(GL_DEPTH_TEST);
  419.  
  420.    if (!(Counter.flags & PRBIT_FLAG)) 
  421.      draw_me(tb,flaggs) ;
  422.  
  423.    if (flaggs->star[flaggs->suun_current].angsiz >= ANGULAR_SIZE)  {
  424.      glDepthFunc(GL_ALWAYS);
  425.  
  426.      theta = 1.5*Counter.D / tb->ptr->yer ;
  427.      i = theta ;
  428.      theta = 360.0*(theta - i) ;
  429.  
  430.      arr[0] = Counter.sky_clear_color[0];
  431.      arr[1] = Counter.sky_clear_color[1];
  432.      arr[2] = 0.06 + 0.94*Counter.sky_clear_color[2];
  433.      arr[3] = Counter.sky_clear_color[3];
  434.      glColor4fv(arr);
  435.  
  436.      p = &flaggs->star[flaggs->suun_current].posit;
  437.  
  438.      glPushMatrix();
  439.      glTranslatef(p->x,p->y,p->z) ;
  440.      glScalef(20000000.0,20000000.0,20000000.0);
  441.      glRotatef((flot32)theta,0.0,1.0,0.0) ; 
  442.      glCullFace(GL_FRONT) ;
  443.      glCallList(Counter.shadowsqobj);
  444.      glCullFace(GL_BACK) ;
  445.      glPopMatrix();
  446.  
  447.      draw_me(&flaggs->star[flaggs->suun_current],flaggs) ;
  448.  
  449.      arr[0] = Counter.sky_clear_color[0];
  450.      arr[1] = Counter.sky_clear_color[1];
  451.      arr[2] = 0.02 + 0.98*Counter.sky_clear_color[2];
  452.      arr[3] = Counter.sky_clear_color[3];
  453.      glColor4fv(arr);
  454.  
  455.      glPushMatrix();
  456.      glTranslatef(p->x,p->y,p->z) ;
  457.      glScalef(20000000.0,20000000.0,20000000.0);
  458.      glRotatef((flot32)theta,0.0,1.0,0.0) ; 
  459.      glCallList(Counter.shadowsqobj);
  460.      glPopMatrix();
  461.  
  462.      glDepthFunc(GL_LEQUAL);
  463.      }
  464.  
  465.    glDisable(GL_DEPTH_TEST);
  466. }
  467.  
  468. /**********************************************************************
  469. *  draw_me()  - 
  470. **********************************************************************/
  471. static void draw_me(t_body *body,t_boss *flaggs)
  472.  
  473. {  register flot64   theta ;
  474.             flot32   whop ;
  475.    register sint32   i,bobj,style,seed,*q = (sint32 *)&whop ;
  476.    register t_stars  *s ;
  477.    register Matrix   m ;
  478.             uchar8   cl[3];
  479.  
  480.    if (sphere_clipp(&body->posit,body->cliprad))  {
  481.      if (body->angsiz > 0.03)
  482.        bobj = body->bodyobj[0] ;
  483.      else if (body->angsiz > 0.003)
  484.        bobj = body->bodyobj[1] ;
  485.      else bobj = body->bodyobj[2] ;
  486.  
  487.      glPushMatrix() ;
  488.      switch ((style = (body->ptr->tess & 0x00f0) >> 4))  {
  489.  
  490.        /* Flat Sphere */
  491.        case FLAT_SPHERE: glTranslatef(body->posit.x,body->posit.y,body->posit.z) ;
  492.                          glScalef(body->ptr->rad,body->ptr->rad,body->ptr->rad) ;
  493.                          spTranMatrix((flot32 *)m,(flot32 *)Counter.mat) ;
  494.                          glMultMatrixf((float*)m) ;
  495.  
  496.                          cl[0] = (body->ptr->col >>  0) & 0xff;
  497.                          cl[1] = (body->ptr->col >>  8) & 0xff;
  498.                          cl[2] = (body->ptr->col >> 16) & 0xff;
  499.                          glColor3ubv(cl) ;
  500.                          glCallList(bobj) ;
  501.                          break ;
  502.  
  503.        /* Lit Sphere */
  504.        case LIGT_SPHERE: glTranslatef(body->posit.x,body->posit.y,body->posit.z) ;
  505.                          glScalef(body->ptr->rad,body->ptr->rad,body->ptr->rad) ;
  506.                          spTranMatrix((flot32 *)m,(flot32 *)Counter.mat) ;
  507.                          glMultMatrixf((float*)m) ;
  508.  
  509.                          glShadeModel(GL_SMOOTH);
  510.  
  511.                          spLightMaterial(1,body->ptr->col);
  512.                          glCallList(bobj) ;
  513.                          spLightMaterial(0,~0);
  514.  
  515.                          glShadeModel(GL_FLAT);
  516.                          break ;
  517.  
  518.        /* Textured Sphere */
  519.        case TEXX_SPHERE: glTranslatef(body->posit.x,body->posit.y,body->posit.z) ;
  520.                          glScalef(body->ptr->rad,body->ptr->rad,body->ptr->rad) ;
  521.  
  522.                          glRotatef(-body->ptr->apo,0.0,0.0,1.0) ; 
  523.                          theta = Counter.D / (body->ptr->day - 1.0/body->ptr->yer) ;
  524.                          i = theta ;
  525.                          theta = 360.0*(theta - i) ;
  526.                          glRotatef((flot32)theta,0.0,1.0,0.0) ; 
  527.  
  528.                          glShadeModel(GL_SMOOTH);
  529.                          spLightMaterial(1,body->ptr->col);
  530.  
  531.                          if (!strcmp(body->ptr->name,"Freedom"))  {
  532.                            glDisable(GL_CULL_FACE) ;
  533. #if 0
  534.                            Ydraw();
  535. #endif
  536.                            glDisable(GL_DEPTH_TEST);
  537.                            glEnable(GL_CULL_FACE) ;
  538.                            }
  539.                          else  {
  540.                            spFlipTex(1,body->texdf) ;
  541.                            glColor4f(1.0,1.0,1.0,1.0);
  542.                            glCallList(bobj) ;
  543.                            spFlipTex(0,0) ;
  544.                            }
  545.  
  546.                          spLightMaterial(0,~0);
  547.                          glShadeModel(GL_FLAT);
  548.                          break ;
  549.  
  550.        /* Fractal/Elevation Planet */
  551.        case FRAC_PLANET: 
  552.        case ELEV_PLANET: planet = body ;
  553.                          glTranslatef(body->posit.x,body->posit.y,body->posit.z) ;
  554.                          glScalef(body->ptr->rad,body->ptr->rad,body->ptr->rad) ;
  555.  
  556.                          glRotatef(-body->ptr->apo,0.0,0.0,1.0) ; 
  557.                          theta = Counter.D / (body->ptr->day - 1.0/body->ptr->yer) ;
  558.                          i = theta ;
  559.                          theta = 360.0*(theta - i) ;
  560.                          glRotatef((flot32)theta,0.0,1.0,0.0) ; 
  561.  
  562.                          if (Counter.flags & REGEN_FLAG) {
  563.                            destroy_fractsphere() ;
  564.                            if (style == ELEV_PLANET)
  565.                              read_data_file(body) ;
  566.                            s = &ggaa[Counter.z][Counter.x].stars[Counter.star_current] ;
  567.                            whop = s->x * s->y * s->z + flaggs->suun_current; 
  568.                            generate_fractsphere(4,*q) ;
  569.                            Counter.flags &= ~REGEN_FLAG ;
  570.                            }
  571.  
  572.                          prepare_for_fractal_planet(flaggs,flaggs->plan_current) ;
  573.                          display_fractsphere() ;
  574.  
  575.                          if (strcmp(body->ptr->name,"Terra") == 0 && GeosphereData)
  576.                            Counter.flags |= GEOSP_FLAG ;
  577.  
  578.                          break ;
  579.  
  580.        case FRAC_RINGWO:
  581.        case ELEV_RINGWO: planet = body ;
  582.                          glTranslatef(flaggs->star[0].posit.x,flaggs->star[0].posit.y,flaggs->star[0].posit.z) ;
  583.                          glScalef(body->ptr->orb,body->ptr->orb,body->ptr->orb) ;
  584.  
  585.                          theta = Counter.D / body->ptr->yer ;
  586.                          i = theta ;
  587.                          theta = 360.0*(theta - i) ;
  588.                          glRotatef((flot32)theta,0.0,1.0,0.0) ; 
  589.  
  590.                          if (Counter.flags & REGEN_FLAG) {
  591.                            destroy_ringworld() ;
  592.                            s = &ggaa[Counter.z][Counter.x].stars[Counter.star_current] ;
  593.                            seed = (flot32) s->x * s->y * s->z * 1234.0 ;
  594.                            generate_ringworld(4,seed) ;
  595.                            Counter.flags &= ~REGEN_FLAG ;
  596.                            }
  597.  
  598.                          prepare_for_fractal_ringworld(flaggs,flaggs->plan_current) ;
  599.                          display_ringworld() ;
  600.                          break ;
  601.  
  602.        default:          printf("Cannot draw this option\n") ;
  603.                          exit(0) ;
  604.                          break ;
  605.        }
  606.      glPopMatrix() ;
  607.  
  608.      if (body->ptr->r1 != 0.0 && body->ptr->r2 != 0.0)  {
  609.        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);  
  610.        glEnable(GL_BLEND);
  611.        glDisable(GL_CULL_FACE) ;
  612.  
  613.        glPushMatrix() ;
  614.        glTranslatef(body->posit.x,body->posit.y,body->posit.z) ;
  615.        glRotatef(-body->ptr->apo,0.0,0.0,1.0) ; 
  616.        glRotatef(Counter.light_angle,0.0,1.0,0.0) ;
  617.  
  618.        spFlipTex(1,body->texrn) ;
  619.  
  620.        if (body->angsiz > 0.15)
  621.          glCallList(body->ringobj[0]) ;
  622.        else if (body->angsiz > 0.01)
  623.          glCallList(body->ringobj[1]) ;
  624.        else glCallList(body->ringobj[2]) ;
  625.  
  626.        spFlipTex(0,0) ;
  627.  
  628.        glPopMatrix() ;
  629.  
  630.        glEnable(GL_CULL_FACE) ;
  631.        glBlendFunc(GL_SRC_ALPHA, GL_ONE);  
  632.        glDisable(GL_BLEND);
  633.        }
  634.      }
  635. }
  636.  
  637. /**********************************************************************
  638. *  sphere_clipp()  -
  639. **********************************************************************/
  640. static sint32 sphere_clipp(register D3 *p,register flot32 rad)
  641.  
  642. {  register flot32 x,y,z,o ;
  643.    register V4     *c = Counter.clop ;
  644.  
  645.    x = p->x ;
  646.    y = p->y ;
  647.    z = p->z ;
  648.    o = -rad ;
  649.  
  650.    if (c->x*x + c->y*y + c->z*z + c->w > o)  {
  651.      c++ ;
  652.      if (c->x*x + c->y*y + c->z*z + c->w > o)  {
  653.        c++ ;
  654.        if (c->x*x + c->y*y + c->z*z + c->w > o)  {
  655.          c++ ;
  656.          if (c->x*x + c->y*y + c->z*z + c->w > o)  {
  657.            c++ ;
  658.            if (c->x*x + c->y*y + c->z*z + c->w > o) 
  659.              return(1) ;
  660.            }
  661.          }
  662.        }
  663.      }
  664.  
  665.    return(0) ;
  666. }
  667.  
  668. /**********************************************************************
  669. *  prepare_for_fractal_planet()  -
  670. **********************************************************************/
  671. static void prepare_for_fractal_planet(t_boss *flaggs,sint32 i)
  672.  
  673. {  register flot64 x,y,z,c1,s1,w,u ;
  674.    register Matrix ma,mb ;
  675.    register sint32 j,b ;
  676.    register t_system *planet ;
  677.    register t_body *tb ;
  678.    register V4     *clop = Counter.clop ;
  679.  
  680.    tb = (t_body *) flaggs->star[flaggs->suun_current].next[i] ;
  681.    planet = tb->ptr ;
  682.  
  683.    x = -tb->posit.x/planet->rad ;
  684.    y = -tb->posit.y/planet->rad ;
  685.    z = -tb->posit.z/planet->rad ;
  686.  
  687.    /*** rot((flot32)theta,'y') ; ***/
  688.    w  = -2.0*M_PI*Counter.D/(planet->day - 1.0/planet->yer) ;
  689.    c1 = cos(w) ;
  690.    s1 = sin(w) ;
  691.    ma[0][0] =  c1 ; ma[0][1] = 0.0 ; ma[0][2] = -s1 ; ma[0][3] = 0.0 ;
  692.    ma[1][0] = 0.0 ; ma[1][1] = 1.0 ; ma[1][2] = 0.0 ; ma[1][3] = 0.0 ;
  693.    ma[2][0] =  s1 ; ma[2][1] = 0.0 ; ma[2][2] =  c1 ; ma[2][3] = 0.0 ;
  694.    ma[3][0] = 0.0 ; ma[3][1] = 0.0 ; ma[3][2] = 0.0 ; ma[3][3] = 1.0 ;
  695.  
  696.    /*** rot(body->ptr->apo,'z') ; ***/
  697.    w  = DTOR*planet->apo ;
  698.    c1 = cos(w) ;
  699.    s1 = sin(w) ;
  700.    mb[0][0] =  c1 ; mb[0][1] =  s1 ; mb[0][2] = 0.0 ; mb[0][3] = 0.0 ;
  701.    mb[1][0] = -s1 ; mb[1][1] =  c1 ; mb[1][2] = 0.0 ; mb[1][3] = 0.0 ;
  702.    mb[2][0] = 0.0 ; mb[2][1] = 0.0 ; mb[2][2] = 1.0 ; mb[2][3] = 0.0 ;
  703.    mb[3][0] = 0.0 ; mb[3][1] = 0.0 ; mb[3][2] = 0.0 ; mb[3][3] = 1.0 ;
  704.    spMultMatrix((flot32 *)ma,(flot32 *)mb,(flot32 *)ma) ;
  705.  
  706.    feye.x = ma[0][0]*x + ma[1][0]*y + ma[2][0]*z ;
  707.    feye.y = ma[0][1]*x + ma[1][1]*y + ma[2][1]*z ;
  708.    feye.z = ma[0][2]*x + ma[1][2]*y + ma[2][2]*z ; 
  709.    feye.w = fsqrt(feye.x*feye.x+feye.y*feye.y+feye.z*feye.z) ;
  710.  
  711.    x = flaggs->star[flaggs->suun_current].posit.x - tb->posit.x ;
  712.    y = flaggs->star[flaggs->suun_current].posit.y - tb->posit.y ;
  713.    z = flaggs->star[flaggs->suun_current].posit.z - tb->posit.z ;
  714.  
  715.    lit.x = ma[0][0]*x + ma[1][0]*y + ma[2][0]*z ;
  716.    lit.y = ma[0][1]*x + ma[1][1]*y + ma[2][1]*z ;
  717.    lit.z = ma[0][2]*x + ma[1][2]*y + ma[2][2]*z ; 
  718.    w = sqrt(lit.x*lit.x+lit.y*lit.y+lit.z*lit.z) ;
  719.    lit.x /= w ; lit.y /= w ; lit.z /= w ;
  720.  
  721.    w = 256.0 * (2.0 - feye.w) ;
  722.    if (w <   0.0) w =   0.0 ;
  723.    if (w > 255.0) w = 255.0 ;
  724.  
  725.    Counter.skyfrac = 0.0;
  726.    u = (lit.x*feye.x + lit.y*feye.y + lit.z*feye.z) / feye.w ; 
  727.  
  728.    if (u > -0.25)   {
  729.      if (Counter.flags & ECLIP_FLAG) 
  730.        w *= 1.0 - Counter.feclipse ;
  731.  
  732.      Counter.skyfrac = w * sqrt(0.8*(u+0.25)) ;
  733.      }
  734.  
  735.    Counter.sky_clear_color[0] = Counter.skyfrac/512.0;
  736.    Counter.sky_clear_color[1] = Counter.skyfrac/512.0;
  737.    Counter.sky_clear_color[2] = Counter.skyfrac/255.0;
  738.    Counter.sky_clear_color[3] = 1.0;
  739.  
  740.    w = 1.0 / tb->angsiz ;
  741.    vids = w - 1.0 ;
  742.  
  743.    for (j=0; j<NUM_CLIP_PLANES; j++)  {
  744.       plum[j].x = ma[0][0]*clop[j].x + ma[1][0]*clop[j].y + ma[2][0]*clop[j].z ;
  745.       plum[j].y = ma[0][1]*clop[j].x + ma[1][1]*clop[j].y + ma[2][1]*clop[j].z ;
  746.       plum[j].z = ma[0][2]*clop[j].x + ma[1][2]*clop[j].y + ma[2][2]*clop[j].z ;
  747.       plum[j].w = -(plum[j].x*feye.x + plum[j].y*feye.y + plum[j].z*feye.z) ;
  748.       }
  749. }
  750.  
  751. /**********************************************************************
  752. *  calc_posit()  -
  753. **********************************************************************/
  754. void calc_posit(register D3 *p,register t_system *planet, register D3 *center,flot32 tilt)
  755.  
  756. {  register flot64 M,v,E,F,l,e,r,sp,cp,ll ;
  757.    register sint32 loop ;
  758.    register Matrix ma ;
  759.    
  760.    if (strcmp(planet->name,"Luna") == 0)  {
  761.      calculate_luna(p,center) ;
  762.      return ;
  763.      }
  764.  
  765.    e = planet->ecc ;
  766.  
  767.    if (e > 0.80)  {
  768.      M = 2.0*M_PI*(Counter.D - planet->ee)/planet->yer ;
  769.  
  770.      loop = (flot32) e * 20.0 ;
  771.  
  772.      for (E=M; loop>0; loop--)
  773.        E = E - (M - E + e*sin(E))/(e*cos(E) - 1.0) ;
  774.  
  775.      v = 2.0*atan(sqrt((1+e)/(1-e))*tan(0.5*E)) ;
  776.      }
  777.    else {
  778.      M = (planet->ee-planet->ww)/360.0 + Counter.D/planet->yer ;
  779.      M = M - (sint32)M ;
  780.      M = 2.0 * M_PI * M ;
  781.  
  782.      if (e != 0.0)  { 
  783.        loop = (flot32) e * 20.0 ;
  784.  
  785.        for (E=M; loop>0; loop--)
  786.          E = M + e*sin(E) ;
  787.  
  788.        v = 2.0*atan(sqrt((1+e)/(1-e))*tan(0.5*E)) ;
  789.        }
  790.  
  791.      else v = E = M ;
  792.      }
  793.  
  794.    l = DTOR*planet->ww + v ;
  795.    r = planet->orb * (1.0 - e*cos(E)) ;
  796.  
  797.    F = l - DTOR*planet->omega ;
  798.    ll = atan2(cos(DTOR*planet->inc)*sin(F),cos(F)) + DTOR*planet->omega ;
  799.  
  800.    sp = sin(F) * sin(DTOR*planet->inc) ;
  801.    cp = sqrt(1.0 - sp*sp) ;
  802.  
  803.    if (tilt == 0.0)  {
  804.      p->x = center->x + r * cp * sin(ll) ;
  805.      p->y = center->y + r * sp ;
  806.      p->z = center->z + r * cp * cos(ll) ;
  807.      }
  808.    else  {
  809.      E = r * cp * sin(ll) ;
  810.      F = r * sp ;
  811.      M = r * cp * cos(ll) ;
  812.  
  813.      cp = cos(-DTOR*tilt) ;
  814.      sp = sin(-DTOR*tilt) ;
  815.      ma[0][0] =  cp ; ma[0][1] =  sp ; ma[0][2] = 0.0 ;
  816.      ma[1][0] = -sp ; ma[1][1] =  cp ; ma[1][2] = 0.0 ;
  817.      ma[2][0] = 0.0 ; ma[2][1] = 0.0 ; ma[2][2] = 1.0 ;
  818.  
  819.      p->x = center->x + ma[0][0]*E + ma[1][0]*F + ma[2][0]*M ;
  820.      p->y = center->y + ma[0][1]*E + ma[1][1]*F + ma[2][1]*M ;
  821.      p->z = center->z + ma[0][2]*E + ma[1][2]*F + ma[2][2]*M ;
  822.      }
  823. }
  824.  
  825. /**********************************************************************
  826. *  polyline_orbits()  -
  827. **********************************************************************/
  828. static void polyline_orbits(t_boss *flaggs)
  829.  
  830. {  register sint32 i,k ;
  831.    register t_body *tb,*tc ;
  832.  
  833.    if (Counter.star_current < 0)
  834.      return ;
  835.  
  836.    if (!(Counter.alpha & HW_MULSA) && (Counter.alpha & HW_AALIN)) 
  837.      glEnable(GL_BLEND);
  838.  
  839.    if (Counter.flags & PRBIT_FLAG)  {
  840.      for (k=0; k<flaggs->suncount; k++)  {
  841.        glColor4f(0.0,1.0,0.0,1.0) ;
  842.        glPushMatrix() ;
  843.        glTranslatef(flaggs->star[k].posit.x,flaggs->star[k].posit.y,flaggs->star[k].posit.z) ;
  844.  
  845.        for (i=0; i<flaggs->star[k].ptr->moon_count; i++)  {
  846.          tb = (t_body *)flaggs->star[k].next[i] ;
  847.  
  848.          if (tb->orbsiz < 0.02)
  849.            glCallList(tb->orbtobj[2]) ;
  850.          else if (tb->orbsiz < 0.35) 
  851.            glCallList(tb->orbtobj[1]) ;
  852.          else glCallList(tb->orbtobj[0]) ;
  853.          }
  854.  
  855.        glPopMatrix() ;
  856.        glColor4f(1.0,1.0,1.0,1.0) ;
  857.  
  858.        for (i=0; i<flaggs->star[k].ptr->moon_count; i++)  {
  859.          tb = (t_body *)flaggs->star[k].next[i] ;
  860.   
  861.          if (tb->orbsiz >= 0.002) 
  862.            spDrawString(tb->posit.x,tb->posit.y,tb->posit.z,tb->ptr->name) ;
  863.          }
  864.        }
  865.      }
  866.  
  867.    if (Counter.flags & MRBIT_FLAG && flaggs->plan_current != -1)  {
  868.      tb = (t_body *)flaggs->star[flaggs->suun_current].next[flaggs->plan_current] ;
  869.  
  870.      glColor4f(0.0,0.0,1.0,1.0) ;
  871.      glPushMatrix() ;
  872.      glTranslatef(tb->posit.x,tb->posit.y,tb->posit.z) ;
  873.  
  874.      for (i=0; i<tb->ptr->moon_count; i++)  {
  875.        tc = (t_body *) tb->next[i] ;
  876.  
  877.        if (tc->orbsiz < 0.02)
  878.          glCallList(tc->orbtobj[2]) ;
  879.        else if (tc->orbsiz < 0.35) 
  880.          glCallList(tc->orbtobj[1]) ;
  881.        else glCallList(tc->orbtobj[0]) ;
  882.        }
  883.  
  884.      glPopMatrix() ;
  885.      glColor4f(1.0,1.0,1.0,1.0) ;
  886.  
  887.      for (i=0; i<tb->ptr->moon_count; i++)  {
  888.        tc = (t_body *) tb->next[i] ;
  889.  
  890.        if (tc->orbsiz > 0.002)
  891.          spDrawString(tc->posit.x,tc->posit.y,tc->posit.z,tc->ptr->name) ;
  892.        }
  893.      }
  894.  
  895.    if (!(Counter.alpha & HW_MULSA) && (Counter.alpha & HW_AALIN))
  896.      glDisable(GL_BLEND);
  897. }
  898.  
  899. /**********************************************************************
  900. *  calculate_luna()  - 
  901. ***********************************************************************/
  902. static void calculate_luna(D3 *luna,D3 *earth) 
  903.  
  904. {  register flot64 T,l,m,o,L,M,lL,X ;
  905.             flot64 lambda,beta,r ;
  906.    register sint32 i ;
  907.  
  908.    T = (Counter.D + 2447891.5 - 2415020.0) / 36525.0 ;
  909.  
  910.    l = DTOR*(270.434164 + T*(481267.883142 - 0.001133*T)) ;
  911.    i = (I2PI * l) ; l = l - 2.0*M_PI*i ;
  912.  
  913.    m = DTOR*(296.104608 + T*(477198.849108 + 0.009192*T)) ;
  914.    i = (I2PI * m) ; m = m - 2.0*M_PI*i ;
  915.  
  916.    o = DTOR*(259.183275 + T*( -1934.142008 + 0.002078*T)) ;
  917.    i = (I2PI * o) ; o = o - 2.0*M_PI*i ;
  918.  
  919.    L = DTOR*(279.696678 + T*( 36000.768925 + 0.000303*T)) ;
  920.    i = (I2PI * L) ; L = L - 2.0*M_PI*i ;
  921.  
  922.    M = DTOR*(358.475833 + T*( 35999.049750 - 0.000150*T)) ;
  923.    i = (I2PI * M) ; M = M - 2.0*M_PI*i ;
  924.    
  925.    lL = 2.0*(l-L) ;
  926.  
  927.    lambda  = 0.0 ;
  928.    lambda += 22640.0*fsin(m) + 769.0*fsin(2.0*m) + 36.0*fsin(3.0*m) ;  /* equation of centre */
  929.    lambda +=  -125.0*fsin(l-L) ;                                       /* parallectic inequality */
  930.    lambda +=  2370.0*fsin(lL) ;                                        /* variation */
  931.    lambda +=  -668.0*fsin(M) ;                                         /* annual equation */
  932.    lambda +=  -412.0*fsin(2.0*(l-o)) ;                                 /* orbit/ecliptic */
  933.    lambda +=   212.0*fsin(2.0*(l-L-m)) ;
  934.    lambda +=  4586.0*fsin(lL-m) ;                                      /* evection */
  935.    lambda +=   192.0*fsin(lL+m) ;
  936.    lambda +=   165.0*fsin(lL-M) ;
  937.    lambda +=   206.0*fsin(lL-m-M) ;
  938.    lambda +=  -110.0*fsin(m+M) ;
  939.    lambda +=   148.0*fsin(m-M) ;
  940.    lambda  = l + DTOR*lambda/3600.0 ; 
  941.  
  942.    X = 2.0*L - l - o ;
  943.  
  944.    beta  = 0.0 ;
  945.    beta += -18520.0*fsin(lambda - o + DTOR*0.114*fsin(2.0*(l-o)) + DTOR*0.150*fsin(M)) ;
  946.    beta +=   -526.0*fsin(X) ;
  947.    beta +=     44.0*fsin(X + m) ;
  948.    beta +=    -31.0*fsin(X - m) ;
  949.    beta +=    -23.0*fsin(X + M) ;
  950.    beta +=     11.0*fsin(X - M) ;
  951.    beta +=    -25.0*fsin(l - o - m - m) ;
  952.    beta +=     21.0*fsin(l - o - m) ;
  953.    beta *= DTOR/3600.0 ;
  954.  
  955.    r  = 3423.0 ;
  956.    r +=  187.0*fcos(m) ;
  957.    r +=   10.0*fcos(m+m) ;
  958.    r +=   34.0*fcos(lL-m) ;
  959.    r +=   28.0*fcos(lL) ;
  960.    r *= DTOR/3600.0 ;
  961.    r  = 6378.14 / fsin(r) ;
  962.  
  963.    luna->x = earth->x + r*fcos(beta)*fsin(lambda) ;
  964.    luna->y = earth->y + r*fsin(beta) ;
  965.    luna->z = earth->z + r*fcos(beta)*fcos(lambda) ;
  966. }
  967.  
  968. /**********************************************************************
  969. *  find_closest_star()  - 
  970. **********************************************************************/
  971. sint32 find_closest_star(sint32 *index,t_galaga *ga)
  972.  
  973. {  register flot32  x,y,z,dmin,r,xc,yc,zc ;
  974.    register sint32  i ;
  975.    register t_stars *st ;
  976.  
  977.    *index = -1 ;
  978.    xc = Counter.eye.x + 0.5*GALAXY_EDGE - (Counter.x+0.5)*EDGESQ ;
  979.    yc = Counter.eye.y ;
  980.    zc = Counter.eye.z + 0.5*GALAXY_EDGE - (Counter.z+0.5)*EDGESQ ;
  981.  
  982.    for (dmin=1.0e12,st=ga->stars,i=0; i<ga->count; st++,i++)  {
  983.      x = st->x - xc ;
  984.      y = st->y - yc ;
  985.      z = st->z - zc ;
  986.  
  987.      r = x*x + y*y + z*z ;
  988.  
  989.      if (r < SOLSYS_EDGE)  {
  990.        *index = i ;
  991.        return(STELL_STAT) ;
  992.        }
  993.      else if (r < dmin)  {
  994.        dmin = r ;
  995.        *index = i ;
  996.        }
  997.      }
  998.  
  999.    return(GALAC_STAT) ;
  1000. }
  1001.  
  1002. /**********************************************************************
  1003. *  display_star_names()  - 
  1004. **********************************************************************/
  1005. static void display_star_names(void)
  1006.  
  1007. {  register sint32    i,count ;
  1008.    register t_stars   *s ;
  1009.    register char      *q ;
  1010.    register flot32    x,y,z,X,Y,Z,d,num ;
  1011.  
  1012.    if (Counter.status == STELL_STAT)  {
  1013.      s = &ggaa[Counter.z][Counter.x].stars[Counter.star_current] ;
  1014.      X = (Counter.x-SOL_X_GRID)*EDGESQ + Counter.eye.x*KMTOPR + s->x ;
  1015.      Y =                                 Counter.eye.y*KMTOPR + s->y ;
  1016.      Z = (Counter.z-SOL_Z_GRID)*EDGESQ + Counter.eye.z*KMTOPR + s->z ;
  1017.      }
  1018.    else  {
  1019.      register D3 pp ;
  1020.  
  1021.      pp.x = -0.5*GALAXY_EDGE + (SOL_X_GRID+0.5)*EDGESQ ;
  1022.      pp.y =  0.0 ;
  1023.      pp.z = -0.5*GALAXY_EDGE + (SOL_Z_GRID+0.5)*EDGESQ ;
  1024.      if (!sphere_clipp(&pp,EDGESQ*EDGESQ)) 
  1025.        return ;
  1026.      X = Counter.eye.x - pp.x ;
  1027.      Y = Counter.eye.y - pp.y ;
  1028.      Z = Counter.eye.z - pp.z ;
  1029.      }
  1030.  
  1031.    glPushMatrix() ;
  1032.    glTranslatef(-X,-Y,-Z) ;
  1033.  
  1034.    glColor4f(0.625,0.625,0.625,1.0) ;
  1035.  
  1036.    count = ggaa[SOL_Z_GRID][SOL_X_GRID].count ;
  1037.    s    = &ggaa[SOL_Z_GRID][SOL_X_GRID].stars[count-1] ;
  1038.  
  1039.    for (num=0.86,q=StarName[count-1],i=count-1; i>0; s--,q-=16,i--) 
  1040.      if (i != Counter.star_current)  {
  1041.        x = s->x - X ;
  1042.        y = s->y - Y ;
  1043.        z = s->z - Z ;
  1044.  
  1045.        d = x*Counter.enorm.x + y*Counter.enorm.y + z*Counter.enorm.z ;
  1046.  
  1047.        if (d*d > num*(x*x+y*y+z*z))
  1048.          spDrawString(s->x,s->y,s->z,q) ;
  1049.        }
  1050.   
  1051.    if (Counter.star_current != 0)  {
  1052.      glColor4f(0.75,0.75,0.0,1.0) ;
  1053.      spDrawString(s->x,s->y,s->z,StarName[0]) ;
  1054.      }
  1055.  
  1056.    glPopMatrix() ;
  1057. }
  1058.  
  1059. /**********************************************************************
  1060. *  total_solar_eclipse()  - 
  1061. **********************************************************************/
  1062. static void total_solar_eclipse(t_boss *flaggs)
  1063.  
  1064. {  T2 t[4] ;
  1065.    P3 p[4] ;
  1066.    V3 vr ;
  1067.    D3 *sp ;
  1068.    flot32 f,w,DD ;
  1069.    uint32 col,r,g,b ;
  1070.  
  1071.    sp = &flaggs->star[flaggs->suun_current].posit;
  1072.  
  1073.    if (!(sphere_clipp(sp,flaggs->star[flaggs->suun_current].cliprad)))
  1074.      return ;
  1075.  
  1076.    DD = flaggs->star[flaggs->suun_current].ptr->rad * (15.0/7.0) ;
  1077.  
  1078.    vr.x = -Counter.light_vector.z ;
  1079.    vr.y =  0.0 ;
  1080.    vr.z =  Counter.light_vector.x ;
  1081.    w = fsqrt(vr.x*vr.x + vr.y*vr.y + vr.z*vr.z) ;
  1082.    vr.x /= w ;
  1083.    vr.y /= w ;
  1084.    vr.z /= w ;
  1085.  
  1086.    t[0].s = 0.0 ;
  1087.    t[0].t = 0.0 ;
  1088.    p[0].x = sp->x - DD*vr.x ;
  1089.    p[0].y = sp->y - DD ; 
  1090.    p[0].z = sp->z - DD*vr.z ;
  1091.  
  1092.    t[1].s = 1.0 ;
  1093.    t[1].t = 0.0 ;
  1094.    p[1].x = sp->x + DD*vr.x ;
  1095.    p[1].y = sp->y - DD ; 
  1096.    p[1].z = sp->z + DD*vr.z ;
  1097.  
  1098.    t[2].s = 1.0 ;
  1099.    t[2].t = 1.0 ;
  1100.    p[2].x = sp->x + DD*vr.x ;
  1101.    p[2].y = sp->y + DD ; 
  1102.    p[2].z = sp->z + DD*vr.z ;
  1103.  
  1104.    t[3].s = 0.0 ;
  1105.    t[3].t = 1.0 ;
  1106.    p[3].x = sp->x - DD*vr.x ;
  1107.    p[3].y = sp->y + DD ; 
  1108.    p[3].z = sp->z - DD*vr.z ;
  1109.  
  1110.    f = 10.0 * (Counter.feclipse - 0.9) ;
  1111.    if (f < 0.0) f = 0.0 ;
  1112.    if (f > 1.0) f = 1.0 ;
  1113.    f /= 256.0;
  1114.  
  1115.    col = flaggs->star[flaggs->suun_current].ptr->col ;
  1116.    r = (col >>  0) & 0xff ;
  1117.    g = (col >>  8) & 0xff ;
  1118.    b = (col >> 16) & 0xff ;
  1119.    glColor4f(r*f,g*f,b*f,1.0) ;
  1120.  
  1121.    glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);  
  1122.    glEnable(GL_BLEND);
  1123.  
  1124.    glBegin(GL_TRIANGLES) ;
  1125.    glTexCoord2fv(&t[0].s) ; glVertex3fv(&p[0].x) ;
  1126.    glTexCoord2fv(&t[1].s) ; glVertex3fv(&p[1].x) ;
  1127.    glTexCoord2fv(&t[2].s) ; glVertex3fv(&p[2].x) ;
  1128.  
  1129.    glTexCoord2fv(&t[2].s) ; glVertex3fv(&p[2].x) ;
  1130.    glTexCoord2fv(&t[3].s) ; glVertex3fv(&p[3].x) ;
  1131.    glTexCoord2fv(&t[0].s) ; glVertex3fv(&p[0].x) ;
  1132.    glEnd() ;
  1133.  
  1134.    glBlendFunc(GL_SRC_ALPHA, GL_ONE);  
  1135.    glDisable(GL_BLEND);
  1136. }
  1137.  
  1138. /**********************************************************************
  1139. *  prepare_for_fractal_ringworld()  -
  1140. **********************************************************************/
  1141. static void prepare_for_fractal_ringworld(t_boss *flaggs,sint32 i)
  1142.  
  1143. {  register flot64 x,y,z,c1,s1,w,u,daylight,epsi ;
  1144.    register sint32 j,b ;
  1145.    register t_system *planet ;
  1146.    register t_body *tb ;
  1147.    register Matrix ma ;
  1148.    register V4     *clop = Counter.clop ;
  1149.  
  1150.    tb = (t_body *) flaggs->star[flaggs->suun_current].next[i] ;
  1151.    planet = tb->ptr ;
  1152.  
  1153.    x = -flaggs->star[flaggs->suun_current].posit.x/planet->orb ;
  1154.    y = -flaggs->star[flaggs->suun_current].posit.y/planet->orb ;
  1155.    z = -flaggs->star[flaggs->suun_current].posit.z/planet->orb ;
  1156.  
  1157.    /*** rot((flot32)theta,'y') ; ***/
  1158.    w  = -2.0*M_PI*Counter.D/planet->yer ;
  1159.    c1 = cos(w) ;
  1160.    s1 = sin(w) ;
  1161.    ma[0][0] =  c1 ; ma[0][1] = 0.0 ; ma[0][2] = -s1 ; ma[0][3] = 0.0 ;
  1162.    ma[1][0] = 0.0 ; ma[1][1] = 1.0 ; ma[1][2] = 0.0 ; ma[1][3] = 0.0 ;
  1163.    ma[2][0] =  s1 ; ma[2][1] = 0.0 ; ma[2][2] =  c1 ; ma[2][3] = 0.0 ;
  1164.    ma[3][0] = 0.0 ; ma[3][1] = 0.0 ; ma[3][2] = 0.0 ; ma[3][3] = 1.0 ;
  1165.  
  1166.    feye.x = ma[0][0]*x + ma[1][0]*y + ma[2][0]*z ;
  1167.    feye.y = ma[0][1]*x + ma[1][1]*y + ma[2][1]*z ;
  1168.    feye.z = ma[0][2]*x + ma[1][2]*y + ma[2][2]*z ; 
  1169.    feye.w = fsqrt(feye.x*feye.x+feye.y*feye.y+feye.z*feye.z) ;
  1170.  
  1171.    x = flaggs->star[flaggs->suun_current].posit.x - tb->posit.x ;
  1172.    y = flaggs->star[flaggs->suun_current].posit.y - tb->posit.y ;
  1173.    z = flaggs->star[flaggs->suun_current].posit.z - tb->posit.z ;
  1174.  
  1175.    epsi = 0.1;
  1176.    vids = 0.0 ;
  1177.  
  1178.    if (feye.y > -RINGWEDGE && feye.y < RINGWEDGE && feye.w > 0.998 && feye.w < 1.0)  {
  1179.      s1 = 0.5*Counter.D / 9.037;
  1180.      s1 = 366.0 - 360.0*(s1 - (long)s1) ;
  1181.      c1 = RTOD*(M_PI + atan2(feye.x,feye.z)) + s1;
  1182.      c1 /= 12.0;
  1183.      b = c1;
  1184.      c1 -= (long)c1;
  1185.  
  1186.      if (b & 1)  {
  1187.        if (c1 < epsi)
  1188.          daylight = 0.5*c1/epsi + 0.5;
  1189.        else if (c1 > 1.0-epsi)
  1190.          daylight = 0.5*(1.0-c1)/epsi + 0.5;
  1191.        else daylight = 1.0;
  1192.        }
  1193.      else  {
  1194.        if (c1 < epsi)
  1195.          daylight = 0.5 - 0.5*c1/epsi;
  1196.        else if (c1 > 1.0-epsi)
  1197.          daylight = 0.5 - 0.5*(1.0-c1)/epsi;
  1198.        else daylight = 0.0;
  1199.        }
  1200.  
  1201.      Counter.skyfrac = 500.0 * (feye.w - 0.998) * daylight ;
  1202.      Counter.sky_clear_color[0] = 0.5*Counter.skyfrac;
  1203.      Counter.sky_clear_color[1] = 0.5*Counter.skyfrac;
  1204.      Counter.sky_clear_color[2] = 1.0*Counter.skyfrac;
  1205.      Counter.sky_clear_color[3] = 1.0;
  1206.      }
  1207.    else  {
  1208.      Counter.skyfrac = 0.0 ;
  1209.      Counter.sky_clear_color[0] = 0.0;
  1210.      Counter.sky_clear_color[1] = 0.0;
  1211.      Counter.sky_clear_color[2] = 0.0;
  1212.      Counter.sky_clear_color[3] = 0.0;
  1213.      }
  1214.  
  1215.    for (j=0; j<NUM_CLIP_PLANES; j++)  {
  1216.       plum[j].x = ma[0][0]*clop[j].x + ma[1][0]*clop[j].y + ma[2][0]*clop[j].z ;
  1217.       plum[j].y = ma[0][1]*clop[j].x + ma[1][1]*clop[j].y + ma[2][1]*clop[j].z ;
  1218.       plum[j].z = ma[0][2]*clop[j].x + ma[1][2]*clop[j].y + ma[2][2]*clop[j].z ;
  1219.       plum[j].w = -(plum[j].x*feye.x + plum[j].y*feye.y + plum[j].z*feye.z) ;
  1220.       }
  1221. }
  1222.  
  1223. /**********************************************************************
  1224. *  draw_all_them_stars()  - 
  1225. **********************************************************************/
  1226. void draw_all_them_stars(sint32 galflag)
  1227.  
  1228. {  register t_stars  *st ;
  1229.    register sint32   i,j,k,stepp,mm[4],*ff,flag[18][18],cheater,*p ;
  1230.    register flot32   x,y,z,cut,one=1.0,xc,yc,zc,mult ;
  1231.             flot32   r ;
  1232.    register char     *ch ;
  1233.    register P3       eye ;
  1234.    register t_galaga *ga ;
  1235.  
  1236.    glEnable(GL_BLEND);
  1237.    if (Counter.flags & NDPNT_FLAG)
  1238.      glDisable(GL_DITHER);
  1239.  
  1240.    if (galflag)  {
  1241.      glPushMatrix() ;
  1242.      glTranslatef(-Counter.eye.x,-Counter.eye.y,-Counter.eye.z) ;
  1243.      glCallList(Counter.starobj) ;
  1244.      glPopMatrix() ;
  1245.  
  1246.      eye.x = Counter.eye.x ;
  1247.      eye.y = Counter.eye.y ;
  1248.      eye.z = Counter.eye.z ;
  1249.      }
  1250.    else  {
  1251.      st = &ggaa[Counter.z][Counter.x].stars[Counter.star_current] ;
  1252.      eye.x = st->x + -0.5*GALAXY_EDGE + (Counter.x+0.5)*EDGESQ ;
  1253.      eye.y = st->y ;
  1254.      eye.z = st->z + -0.5*GALAXY_EDGE + (Counter.z+0.5)*EDGESQ ;
  1255.      }
  1256.  
  1257.    p = (sint32 *)&r ;
  1258.    cheater = ((Counter.z == SOL_Z_GRID && Counter.x == SOL_X_GRID) ? 1 : 0) ;
  1259.    stepp = (cheater ? 0 : 8) ; 
  1260.  
  1261.    mm[0] = Counter.z - stepp ; if (mm[0] <       0) mm[0] = 0 ;
  1262.    mm[1] = Counter.z + stepp ; if (mm[1] >= STARSQ) mm[1] = STARSQ-1 ;
  1263.    mm[2] = Counter.x - stepp ; if (mm[2] <       0) mm[2] = 0 ;
  1264.    mm[3] = Counter.x + stepp ; if (mm[3] >= STARSQ) mm[3] = STARSQ-1 ;
  1265.  
  1266.    if (!cheater)
  1267.      star_square_clip_check(mm,flag,&eye) ;
  1268.  
  1269.    yc = eye.y ;
  1270.    zc = 0.5*GALAXY_EDGE - (mm[0]+0.5)*EDGESQ + eye.z ;
  1271.  
  1272.    for (k=mm[0]; k<=mm[1]; zc-=EDGESQ,k++)  {
  1273.      xc = 0.5*GALAXY_EDGE - (mm[2]+0.5)*EDGESQ + eye.x ;
  1274.      ff = flag[k-mm[0]] ;
  1275.      ga = &ggaa[k][mm[2]] ;
  1276.  
  1277.      for (j=mm[2]; j<=mm[3]; xc-=EDGESQ,ff++,ga++,j++)
  1278.  
  1279.        if (Counter.x == j && Counter.z == k)  {
  1280.          glPushMatrix() ;
  1281.          glTranslatef(-xc,-yc,-zc) ;
  1282.          st = &ga->stars[ga->count-1];
  1283.          cut = Counter.cutoff ;
  1284.  
  1285.          glBegin(GL_POINTS) ;
  1286.          for (i=ga->count-Counter.star_current-1; i>0; i--,st--)  {
  1287.            x = st->x - xc ;
  1288.            y = st->y - yc ;
  1289.            z = st->z - zc ;
  1290.            r = x*x + y*y + z*z ;
  1291.  
  1292.            ch = (char *)lut + ((*p>>19)<<2) ;
  1293.            st->a = st->fny_mag * *(flot32 *)ch ;
  1294.            if (st->a > one)
  1295.              st->a = one ;
  1296.  
  1297.            if (st->a > cut)  {
  1298.              glColor4fv(&st->r) ;
  1299.              glVertex3fv(&st->x) ;
  1300.              }
  1301.            }
  1302.          for (st--,i=Counter.star_current; i>0; i--,st--) {
  1303.            x = st->x - xc ;
  1304.            y = st->y - yc ;
  1305.            z = st->z - zc ;
  1306.            r = x*x + y*y + z*z ;
  1307.  
  1308.            ch = (char *)lut + ((*p>>19)<<2) ;
  1309.            st->a = st->fny_mag * *(flot32 *)ch ;
  1310.            if (st->a > one)
  1311.              st->a = one ;
  1312.  
  1313.            if (st->a > cut)  {
  1314.              glColor4fv(&st->r) ;
  1315.              glVertex3fv(&st->x) ;
  1316.              }
  1317.            }
  1318.          glEnd() ;
  1319.  
  1320.          glPopMatrix() ;
  1321.          }
  1322.  
  1323.        else if (!(*(ff+0) & *(ff+1) & *(ff+18) & *(ff+19)))  {
  1324.          glPushMatrix() ;
  1325.          glTranslatef(-xc,-yc,-zc) ;
  1326.          st = &ga->stars[ga->count-1];
  1327.          cut = Counter.cutoff;
  1328.  
  1329.          r = xc*xc + yc*yc + zc*zc ;
  1330.          ch = (char *)lut + ((*p>>19)<<2) ;
  1331.          mult = *(flot32 *)ch ;
  1332.  
  1333.          glBegin(GL_POINTS) ;
  1334.          for (i=ga->count; i>0; i--,st--)  {
  1335.            st->a = st->fny_mag*mult ;
  1336.            if (st->a > one) 
  1337.              st->a = one ;
  1338.  
  1339.            if (st->a > cut) {
  1340.              glColor4fv(&st->r) ;
  1341.              glVertex3fv(&st->x) ;
  1342.              }
  1343.            }
  1344.          glEnd() ;
  1345.  
  1346.          glPopMatrix() ;
  1347.          }
  1348.      }
  1349.  
  1350.    if (Counter.flags & NDPNT_FLAG)
  1351.      glEnable(GL_DITHER);
  1352.    glDisable(GL_BLEND);
  1353. }
  1354.  
  1355. /**********************************************************************
  1356. *  read_data_file()  - 
  1357. **********************************************************************/
  1358. static void read_data_file(t_body *body)
  1359.  
  1360. {  FILE   *fd ;
  1361.    sint32 bytes ;
  1362.  
  1363.    if (strcmp(body->ptr->elev,mem_ele_nme))  {
  1364.      if (body->ptr->elev[0] != '\0' && (fd = fopen(datatrail(body->ptr->elev),"r"))) {
  1365.        bytes = (((body->ptr->lformat&0xf) + 1) >> 1) * body->ptr->lxsize * body->ptr->lysize ;
  1366.  
  1367.        if (bytes > MAX_ELEV_BYTES)  {
  1368.          printf("INTERNAL ERROR: Data file too large: %s\n",datatrail(body->ptr->elev)) ;
  1369.          exit(0) ;
  1370.          }
  1371.  
  1372.        stall_message("Please Wait: Loading Data File",0.4,0.5) ;
  1373.  
  1374.        body->land = mem_ele_ptr ;
  1375.        fread(body->land,bytes,body->ptr->lxsize*body->ptr->lysize,fd) ;
  1376.        fclose(fd) ;
  1377.        }
  1378.      else  {
  1379.        printf("USER ERROR: Data file not found: %s\n",datatrail(body->ptr->elev)) ;
  1380.        exit(0) ;
  1381.        }
  1382.  
  1383.      strcpy(mem_ele_nme,body->ptr->elev) ;
  1384.      }
  1385.  
  1386.    if (strcmp(body->ptr->colr,mem_col_nme))  {
  1387.      if (body->ptr->colr[0] != '\0' && (fd = fopen(datatrail(body->ptr->colr),"r"))) {
  1388.        bytes = (((body->ptr->cformat&0xf) + 1) >> 1) * body->ptr->cxsize * body->ptr->cysize ;
  1389.  
  1390.        if (bytes > MAX_COLR_BYTES)  {
  1391.          printf("INTERNAL ERROR: Data file too large: %s\n",datatrail(body->ptr->colr)) ;
  1392.          exit(0) ;
  1393.          }
  1394.  
  1395.        stall_message("Please Wait: Loading Data File",0.4,0.5) ;
  1396.  
  1397.        body->colr = mem_col_ptr ;
  1398.        fread(body->colr,bytes,body->ptr->cxsize*body->ptr->cysize,fd) ;
  1399.        fclose(fd) ;
  1400.        }
  1401.  
  1402.      strcpy(mem_col_nme,body->ptr->colr) ;
  1403.      }
  1404. }
  1405.  
  1406. /**********************************************************************
  1407. *  stall_message()  - 
  1408. **********************************************************************/
  1409. static void stall_message(char *st,flot32 x,flot32 y)
  1410.  
  1411. {  register flot32 dx = 1.0/Counter.winsizex ;
  1412.    register flot32 dy = 1.0/Counter.winsizey ;
  1413.    register sint32 ln = strlen(st) ;
  1414.  
  1415.    Counter.flags |= FREEZ_FLAG ;
  1416.  
  1417.    spSwapBuffers();
  1418.    glPushMatrix() ;
  1419.  
  1420.    glMatrixMode(GL_PROJECTION);
  1421.    glLoadIdentity();
  1422.    glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0) ;
  1423.    glMatrixMode(GL_MODELVIEW);
  1424.    glLoadIdentity();
  1425.  
  1426.    glColor4f(1.0,0.0,0.0,1.0) ;
  1427.    glRectf(x-4.0*dx,y-4.0*dy,x+(9.0*ln+4.0)*dx,y+14.0*dy) ;
  1428.  
  1429.    glColor4f(1.0,1.0,1.0,1.0) ;
  1430.    spDrawString(x,y,0.0,st) ;
  1431.  
  1432.    glPopMatrix() ;
  1433.    spSwapBuffers();
  1434. }
  1435.  
  1436. /**********************************************************************
  1437. *  special_perspective()  - 
  1438. **********************************************************************/
  1439. void special_perspective(register flot32 min,register flot32 max)
  1440.  
  1441. {  float fov,top,bot,rig,lef,dx,dy,dz;
  1442.  
  1443.    if (Counter.flags & ACCUM_FLAG) {
  1444.      fov = Counter.viewangle*M_PI/3600.0;
  1445.      top = min*fsin(fov)/fcos(fov);
  1446.      bot = -top;
  1447.      rig = top * Counter.aspcratio;
  1448.      lef = -rig;
  1449.   
  1450.      dx = -Counter.acdx * (rig - lef)/1280.0;     
  1451.      dy = -Counter.acdy * (top - bot)/1024.0;     
  1452.  
  1453.      glMatrixMode(GL_PROJECTION) ;
  1454.      glLoadIdentity();
  1455.      glFrustum(lef+dx,rig+dx,bot+dy,top+dy,min,max);
  1456.      glMatrixMode(GL_MODELVIEW) ;
  1457.      }
  1458.    else  {
  1459.      glMatrixMode(GL_PROJECTION) ;
  1460.      spPerspMatrix(min,max);
  1461.      glMatrixMode(GL_MODELVIEW) ;
  1462.      }
  1463. }
  1464.  
  1465. /**********************************************************************
  1466. *  accumulation()  - 
  1467. **********************************************************************/
  1468. void accumulation(t_boss *flaggs)
  1469.  
  1470.    
  1471. }
  1472.  
  1473.